package com.zhixiang.xaec.entity.system;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.activiti.engine.identity.Group;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
import org.hibernate.cfg.Comment;
import org.springframework.security.GrantedAuthority;

@Entity
@Table(name = "sys_app_role")
@Comment("角色")
public class AppRole implements GrantedAuthority, Group {

	private static final long serialVersionUID = 4727154426117391857L;
	public static String ROLE_PUBLIC = "ROLE_PUBLIC";
	public static String ROLE_ANONYMOUS = "ROLE_ANONYMOUS";
	public static final Long SUPER_ROLEID = Long.valueOf(-1L);
	public static final String SUPER_RIGHTS = "__ALL";

	@Id
	@GenericGenerator(name = "idGenerator",strategy = "com.zhixiang.core.util.IdGenerator")
	@GeneratedValue(generator = "idGenerator")
	private Long roleId;

	@Comment("角色名称")
	private String roleName;

	@Comment("角色描述")
	private String roleDesc;

	@Comment("角色状态")
	private Short status;

	private Short isDefaultIn = 0;

	@Column(length=65535)
	@Type(type = "text")
	@Comment("角色模块")
	private String rights;
	
	@OneToMany(mappedBy = "appRole",cascade={CascadeType.REMOVE,CascadeType.MERGE},fetch=FetchType.LAZY)
	private Set<AppFunction> functions = new HashSet<AppFunction>();
	
//	@ManyToMany(mappedBy="appRoles")
//	@XmlTransient
//	private Set<AppUser> appUsers = new HashSet<AppUser>();

	public Short getIsDefaultIn() {
		return this.isDefaultIn;
	}

	public void setIsDefaultIn(Short paramShort) {
		this.isDefaultIn = paramShort;
	}

//	public Set<AppUser> getAppUsers() {
//		return this.appUsers;
//	}
//
//	public void setAppUsers(Set<AppUser> paramSet) {
//		this.appUsers = paramSet;
//	}

	public String getRights() {
		return this.rights;
	}

	public void setRights(String paramString) {
		this.rights = paramString;
	}

	public Long getRoleId() {
		return this.roleId;
	}

	public void setRoleId(Long paramLong) {
		this.roleId = paramLong;
	}

	public String getRoleName() {
		return this.roleName;
	}

	public void setRoleName(String paramString) {
		this.roleName = paramString;
	}

	public String getRoleDesc() {
		return this.roleDesc;
	}

	public void setRoleDesc(String paramString) {
		this.roleDesc = paramString;
	}

	public Short getStatus() {
		return this.status;
	}

	public void setStatus(Short paramShort) {
		this.status = paramShort;
	}

	public String getAuthority() {
		return this.roleName;
	}

	public int compareTo(Object paramObject) {
		return 0;
	}

	public String getId() {
		return this.roleId.toString();
	}

	public String getName() {
		return this.roleName;
	}

	public String getType() {
		return "candidate";
	}

	public Set<AppFunction> getFunctions() {
		return this.functions;
	}

	public void setFunctions(Set<AppFunction> paramSet) {
		this.functions = paramSet;
	}

    @Override
    public void setId(String arg0)
    {}

    @Override
    public void setName(String arg0)
    {}

    @Override
    public void setType(String arg0)
    {}
}
